package com.example.testproject.activity

import android.annotation.SuppressLint
import android.graphics.Color
import android.graphics.Paint
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import com.example.testproject.R
import com.example.testproject.utils.toast
import com.google.android.material.shape.MaterialShapeDrawable
import com.google.android.material.shape.RoundedCornerTreatment
import com.google.android.material.shape.ShapeAppearanceModel
import com.google.android.material.shape.TriangleEdgeTreatment
import kotlinx.android.synthetic.main.activity_motion_layout.*

/**
 *
 * @ClassName: MotionLayoutActivity
 * @Author: android 超级兵
 * @CreateDate: 12/24/21$ 9:24 AM$
 * TODO MotionLayout布局测试
 *  官方文档:https://developer.android.com/training/constraint-layout/motionlayout#additional_motionlayout_attributes
 */
class MotionLayoutActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_motion_layout)

        // 参考文档:https://mp.weixin.qq.com/s/XGPFPFEr0Rn3GkwqoMaTqA
//        text1()

        text2()


    }

    /*
     * 作者:android 超级兵
     * 创建时间: 12/24/21 10:42 AM
     * TODO 设置阴影
     */
    @SuppressLint("RestrictedApi")
    private fun text2() {
        val shapePathModel = ShapeAppearanceModel.builder()
            .setAllCorners(RoundedCornerTreatment())
            .setAllCornerSizes(16f)
            .build()

        val backgroundDrawable = MaterialShapeDrawable(shapePathModel).apply {
            // 设置本身颜色
            setTint(Color.parseColor("#05bebebe"))
            paintStyle = Paint.Style.FILL
            shadowCompatibilityMode = MaterialShapeDrawable.SHADOW_COMPAT_MODE_ALWAYS
//            shadowCompatibilityMode = MaterialShapeDrawable.SHADOW_COMPAT_MODE_DEFAULT
            initializeElevationOverlay(this@MotionLayoutActivity)
            // 圆角
            shadowRadius = 16
            // 阴影颜色
            setShadowColor(Color.parseColor("#D2D2D2"))
//            setShadowColor(Color.parseColor("#FF00FF"))
            // 阴影深度
            shadowVerticalOffset = 2
        }
        (view.parent as? ViewGroup)?.clipChildren = false
        view.background = backgroundDrawable
    }

    /*
     * 作者:android 超级兵
     * 创建时间: 12/24/21 10:42 AM
     * TODO 圆角
     */
    private fun text1() {
        val shapePathModel = ShapeAppearanceModel.builder()
            .setAllCorners(RoundedCornerTreatment())
            .setAllCornerSizes(10f)
            .setAllEdges(TriangleEdgeTreatment(12f, true))
            .build()

        val backgroundDrawable = MaterialShapeDrawable(shapePathModel).apply {
            setTint(Color.parseColor("#bebebe"))
            paintStyle = Paint.Style.FILL
        }
        view.background = backgroundDrawable
    }

    fun onMotionViewClick(view: View) {
        "点击了".toast(this)
    }
}